package com.bit101.components
{
	import events.CategoryEvent;
	
	import flash.display.DisplayObjectContainer;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	public class NavBtn extends ImageButton
	{
		public var btnList:VBox;
		public function NavBtn(parent:DisplayObjectContainer=null, xpos:Number=0, ypos:Number=0, width:Number=0, 
							   height:Number=0, sourceurl:String=null, defaultHandler:Function=null,data:Object=null)
		{
			super(parent, xpos, ypos, width, height, sourceurl, defaultHandler);
			this.data = data;
		}
		public function setDropList(ary:Array):void{
			btnList = new VBox();
			btnList.spacing = 1;
			btnList.y = this.height;
			btnList.visible = false;
			
			for(var i:int;i<ary.length;i++){
				var btn:ImageButton = new ImageButton(btnList,0,0,0,0,"assets/btns/" +ary[i].url,itemClick);
				btn.data = ary[i];
			}
			
			this.addChild(btnList);
		}
		override public function onMouseOver(event:MouseEvent):void{
			btnList.visible = true;
			this.graphics.clear();
			graphics.beginFill(0xff0000,0);
			graphics.drawRect(0,0,width,height);
			graphics.endFill();
		}
		override public function onMouseOut(event:MouseEvent):void{
			btnList.visible = false;
			graphics.clear();
		}
		override public function onComplete(evnet:Event):void{
			super.onComplete(evnet);
			setDropList(data.data);
		}
		private function itemClick(event:MouseEvent):void{
			var obj:Object = event.currentTarget.data;
			var evt:CategoryEvent = new CategoryEvent(CategoryEvent.CATEGORYEVENT);
			evt.data = obj;
			this.parent.parent.dispatchEvent(evt);
		}
	}
}